package ex03.connector.http;

/**
 * @packgeName: ex03.connector.http
 * @ClassName: HttpRequestLine
 * @copyright: CopyLeft
 * @description:<描述>
 * @author: lili
 * @date: 2017/8/11-17:19
 * @version: 1.0
 * @since: JDK 1.8
 */
final class HttpRequestLine {

    public static final int INITIAL_METHOD_SIZE = 8;
    public static final int INITIAL_URI_SIZE = 64;
    public static final int INITIAL_PROTOCOL_SIZE = 8;
    public static final int MAX_METHOD_SIZE = 1024;
    public static final int MAX_URI_SIZE = 32768;   //2^16
    public static final int MAX_PROTOCOL_SIZE = 1024;


    //对外暴露公有属性
    public char[] method;
    public int methodEnd;
    public char[] uri;
    public int uriEnd;
    public char[] protocol;
    public int protocolEnd;

    public HttpRequestLine(char[] method, int methodEnd,
                           char[] uri, int uriEnd,
                           char[] protocol, int protocolEnd) {
        this.method = method;
        this.methodEnd = methodEnd;
        this.uri = uri;
        this.uriEnd = uriEnd;
        this.protocol = protocol;
        this.protocolEnd = protocolEnd;
    }

    public HttpRequestLine(){
        this(new char[INITIAL_METHOD_SIZE],0,
                new char[INITIAL_URI_SIZE],0,
                new char[INITIAL_PROTOCOL_SIZE],0);
    }

    public void recycle(){
        methodEnd = 0;
        uriEnd = 0;
        protocolEnd = 0;
    }

    //方法重载
    public int indexOf(char[] buf){
        return indexOf(buf,buf.length);
    }

    public int indexOf(char[] buf, int end){
        // TODO: 2017/8/28
        return 0;
        
    }

    public int indexOf(String str){
        return indexOf(str.toCharArray(),str.length());
    }

    public int indexOf(char c, int start){
        for (int i = start; i < uriEnd; i++) {
            if(uri[i] == c){
                return i;
            }
        }
        return -1;
    }

    //Fix Me
    @Override
    public int hashCode() {
        return 0;
    }

    @Override
    public boolean equals(Object obj) {
        return false;
    }
}
